package be.rubengerits.bluetooth.tester;
import android.app.*;
import android.os.*;
import android.content.*;
import android.widget.*;
import android.view.*;

public class FilePickerDialogFragment extends DialogFragment {

public interface FilePickerDialogListener {
        public void onDialogPositiveClick(DialogFragment dialog);
        public void onDialogNegativeClick(DialogFragment dialog);
    }
	
	private FilePickerDialogListener mListener;
	
	@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
		LayoutInflater inflater = getActivity().getLayoutInflater(); 
		
        // Build the dialog and set up the button click handlers
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.file_chooser_title);
		builder.setMessage(R.string.file_chooser_message);
		builder.setView(inflater.inflate(R.layout.main, null) );
		builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					// Send the positive button event back to the host activity
					mListener.onDialogPositiveClick(FilePickerDialogFragment.this);
				}
			});
		builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					// Send the negative button event back to the host activity
					mListener.onDialogPositiveClick(FilePickerDialogFragment.this);
				}
			});
        return builder.create();
    }
	
	@Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        try {
            mListener = (FilePickerDialogListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString() + " must implement FilePickerDialogListener");
        }
    }

}
